package JavaTest.polymorphic.polymorphicArray;

public class PolyArray {
    public static void main(String[] args) {
        //创建Student，Teacher，统一放在数组中，并调用每个对象say方法
        Person[] people = new Person[5];
        people[0] = new Person("Jack",20);
        people[1] = new Student("json",18,90);
        people[2] = new Student("object",18, 95);
        people[3] = new Teacher("bitch",35,3000);
        people[4] = new Teacher("sucker",35, 2800);

        for (Person p :
                people) {
            //动态绑定机制
            System.out.println(p.say());

            if(p instanceof Student){
                ((Student) p).study();
            }else if (p instanceof Teacher){
                ((Teacher) p).teach();
            }else {
                System.out.println("p是个人");
            }
        }
    }
}
